package hc.j2me.util;

import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;

import hc.core.util.ILog;

public class J2MERMSLog implements ILog {
	int size = 0;
	RecordStore rs = buildRMSOut();
	
	private RecordStore buildRMSOut(){
		String rms = "log";
		RecordStore newrs = null;
		try {
			newrs = RecordStore.openRecordStore(rms, true, RecordStore.AUTHMODE_ANY, false);
			System.out.println("Succ RMS Share");
			
			RecordEnumeration re = newrs.enumerateRecords(null, null, false);
			
			while(re.hasNextElement()){
				int rid = re.nextRecordId();
				newrs.deleteRecord(rid);
			}
		} catch (RecordStoreException e) {
			e.printStackTrace();
		}
		
		return newrs;
	}
	
	public void log(String msg) {
		byte[] bs = msg.getBytes();
		try {
			rs.addRecord(bs, 0, bs.length);
		} catch (RecordStoreException e) {
			e.printStackTrace();
		}
		System.out.println(msg);
	}

	public void errWithTip(String msg) {
	}


	public void err(String msg) {
	}
	
	public void info(String msg) {
	}

	public void exit() {
		try{
			rs.closeRecordStore();
		}catch (Exception e) {
			
		}
	}

	public void flush() {
	}

}
